﻿using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Klinkby.MicroBus
{
    /// <summary>
    /// Event arguments passed when an async process completes
    /// </summary>
    [Serializable]
    public class ProcessCompletedEventArgs : EventArgs
    {
        readonly bool _cancelled;
        readonly Exception _error;
        readonly object _state;

        /// <summary>
        /// Creates a ProcessCompletedEventArgs immutable object
        /// </summary>
        /// <param name="cancelled">True if operation was cancelled (currently unsupported)</param>
        /// <param name="error">null (Nothing) if no error occurred</param>
        /// <param name="state">The state passed to the ProcessAsync method</param>
        [DebuggerStepThrough]
        public ProcessCompletedEventArgs(bool cancelled, Exception error, object state)
        {
            _cancelled = cancelled;
            _error = error;
            _state = state;
        }
        /// <summary>
        /// Determines if the operation was actively cancelled
        /// </summary>
        public bool Cancelled
        {
            [DebuggerStepThrough]
            get { return _cancelled; }
        }
        /// <summary>
        /// null (Nothing) if no error occurred
        /// </summary>
        public Exception Error
        {
            [DebuggerStepThrough]
            get { return _error; }
        }
        /// <summary>
        /// The state passed to the ProcessAsync method
        /// </summary>
        public object State
        {
            [DebuggerStepThrough]
            get { return _state; }
        }
    }
}
